#ifndef GAME_WIDGET_H
#define GAME_WIDGET_H

#include <QObject>
#include <QWidget>

#include <QDebug>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <constant.h>
struct TableUser;
class FrameLayout :public QLayout
{
    Q_OBJECT
    QVector<QLayoutItem *> children;
public:
    FrameLayout(QWidget *parent=nullptr);
    void addWidget(QWidget *w, Qt::Alignment alignment = Qt::Alignment());
    void setGeometry(const QRect &rect) override;
    QSize sizeHint() const override;
    QSize minimumSize() const override;
public:
    void addItem(QLayoutItem *item) override;;
    QLayoutItem *itemAt(int index) const override;;
    QLayoutItem *takeAt(int index) override;;
    int count() const override;;
    ~FrameLayout();
private:
    void doLayout(const QRect &rect);
};

class CardPlayWidget :public QWidget
{
    Q_OBJECT
private:
    QSize total_width_size;
    QVector<dymy::CARD_t> cards;
    QVector<bool> cards_selected;
    int card_width=50;
    int card_height=50;
    int show_width=20;
    int selected_top_height = 20;
public:
    explicit CardPlayWidget(QWidget *parent = nullptr);;
    QVector<dymy::CARD_t> get_selected_cards();
    QSize minimumSizeHint() const override;
    QSize sizeHint() const override;
    void clear_cards();
    void set_cards(const  QVector<dymy::CARD_t> &c);
    void setCardSize(int width,int height,int showWidth);
    void mouseReleaseEvent(QMouseEvent *event) override;
    QString to_card_num(dymy::CARD_t card);
    void to_card_type(dymy::CARD_t card,QString &type, QColor &color);
    void paintEvent(QPaintEvent *event) override;
private :
    void calc_size();
};
class TableSelfWidget :public QWidget
{
    Q_OBJECT
signals:
    void prepare_clicked(bool prepare);
    void rob_clicked(bool rob);
    void cards_clicked(const QVector<dymy::CARD_t> &cards);
    void no_cards_clicked();
private:
    const TableUser *user_info;
    QHBoxLayout *layout_info;
    QLabel *label_user_name;
    QLabel *label_prepare;

    QLabel *label_role;
    QLabel *label_cards_num;
    QLabel *label_status;

    QPushButton *button_prepare;
    QPushButton *button_rob;
    QPushButton *button_no_rob;
    QPushButton *button_cards;
    QPushButton *button_no_cards;

    QHBoxLayout *layout_operation;
    CardPlayWidget *card_play;
    CardPlayWidget *max_card_widget;
    QVBoxLayout *layout_container;
public:
    TableSelfWidget(QWidget *parent = nullptr);
    void setUserInfo(const TableUser * const &user,const QVector<dymy::CARD_t> &max_cards= QVector<dymy::CARD_t>());
};

class TableOtherUserWidget :public QWidget
{
    Q_OBJECT
private:
    const TableUser *user_info;
    QHBoxLayout *layout_container;
    QVBoxLayout *layout_info;
    QLabel *label_user_name;
    QLabel *label_prepare;

    QLabel *label_role;
    QLabel *label_cards_num;
    QLabel *label_status;

    CardPlayWidget *max_card_widget;

    QVBoxLayout *layout_out;
    QWidget *widget_hit;

    void set_hit_visible(bool visible);
public:
    TableOtherUserWidget(QWidget *parent);
    void setUserInfo(const TableUser * const &user ,const QVector<dymy::CARD_t> &max_cards= QVector<dymy::CARD_t>());
};
#endif // GAME_WIDGET_H
